package esception;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class text03 {

    public static void main(String[] args) throws IOException {

        /*
        Student zs = new Student();
        try {
            zs.setAge(1000);
            System.out.println("此人年龄为；"+zs.getAge()+"岁");
        }catch (RuntimeException e){
            System.out.println("年龄不合法");
        }

         */


        /*
        Student zs = new Student();
        try {
            zs.setAge(1000);
            System.out.println("此人的年龄为："+zs.getAge()+"岁");
        }catch (RuntimeException e){
            System.out.println("年龄不合法");
        }

         */


        /*
        System.out.println("程序开始了");
        try (FileOutputStream fos = new FileOutputStream("fos.dat")){
            fos.write(1);
        }catch (IOException e){
            e.printStackTrace();
        }
        System.out.println("程序结束了");


         */

        /*
        System.out.println("程序开始了");
        try (
            FileOutputStream fos = new FileOutputStream("fos.dat");
        ){
            fos.write(1);
        }catch (IOException e){
            e.printStackTrace();
        }
        System.out.println("程序结束了");


         */

        /*
        System.out.println("程序开始了");
        FileOutputStream fos = null;
        try {
            fos =  new FileOutputStream("./a/b/fos.dat");
        }catch (IOException e){
            System.out.println("出现IO异常并解决了");
        }finally {
            try {
                if (fos!=null){
                    fos.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        System.out.println("程序结束了");


         */

        /*
        System.out.println("程序开始了");
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("./a/b/fos.dat");
            fos.write(1);
        }catch (IOException e){
            System.out.println("出现IO异常并解决了");
        }finally {
            try {
                if (fos!=null){
                    fos.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        System.out.println("程序结束了");


         */

        /*
        System.out.println("程序开始了");
        try {
            String line = "";
            System.out.println(line.length());
            return;
        }catch (Exception e){
            System.out.println("出错并解决了");
        }finally {
            System.out.println("finally中的代码执行了");
        }
        System.out.println("程序结束了");


         */

        /*
        System.out.println("程序开始了...");
        try {
            String line = "";
            System.out.println(line.length());
        }catch (Exception e){
            System.out.println("出错并解决了");
        }finally {
            System.out.println("finally中的代码执行了");
        }
        System.out.println("程序结束了");


         */



        /*
        System.out.println();
        try {
            String line = null;
            System.out.println();
            String line1 = "";
            System.out.println();
            String line2 = "abc";
            System.out.println(Integer.parseInt(line2));
        }catch (NullPointerException e){
            System.out.println("出现了空指针异常并解决了");
        }catch (StringIndexOutOfBoundsException e){
            System.out.println("出现了字符串下标异常并解决了");
        }catch (Exception e){
            System.out.println("反正就是出了错，就是解决了");
        }
        System.out.println("程序结束了");


         */

        /*
        System.out.println("程序开始了");
        try {
            String line = null;
            System.out.println(line.length());
            String line1 = "";
            System.out.println(line.charAt(0));
            String line2 = "abc";
            System.out.println(Integer.parseInt(line2));
        }catch (NullPointerException e) {
            System.out.println("出现了空指针异常并解决了");
        }catch (StringIndexOutOfBoundsException e){
            System.out.println("出现了字符串下标越界异常并解决了");
        }catch (Exception e){
            System.out.println("反正就是出错了，反正就解决了");
        }
        System.out.println("程序结束了");


         */

        /*
        FileInputStream fis = new FileInputStream("pw.txt");
        InputStreamReader isr = new InputStreamReader(fis,StandardCharsets.UTF_8);
        BufferedReader br = new BufferedReader(isr);
        String line;
        while ((line=br.readLine())!=null){
            System.out.println(line);
        }
        br.close();


         */

        /*
        FileInputStream fis = new FileInputStream("pw.txt");
        InputStreamReader isr = new InputStreamReader(fis,StandardCharsets.UTF_8);
        BufferedReader br = new BufferedReader(isr);
        String line;
        while ((line=br.readLine())!=null){
            System.out.println(line);
        }
        br.close();


         */


        /*
        FileOutputStream fos = new FileOutputStream("pw.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos,StandardCharsets.UTF_8);
        BufferedWriter bw = new BufferedWriter(osw);
        PrintWriter pw = new PrintWriter(bw,true);
        Scanner scan = new Scanner(System.in);
        System.out.println("请开始输入内容，单独输入exit时退出");
        while (true){
            String line = scan.nextLine();
            if ("exit".equals(line)){
                break;
            }
            pw.println(line);
        }
        pw.close();



         */
        /*
        FileOutputStream fos = new FileOutputStream("pw.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        BufferedWriter bw = new BufferedWriter(osw);
        PrintWriter pw = new PrintWriter(bw,true);
        Scanner scan = new Scanner(System.in);
        System.out.println("请开始输入内容，单独输入exit时退出");
        while (true){
            String line = scan.nextLine();
            if ("exit".equals(line)){
                break;
            }
            pw.println(line);
        }
        pw.close();

         */
    }
}

